package cn.zyq.ykb.controller.mgt.user;

import org.springframework.security.access.prepost.PreAuthorize;
import cn.zyq.ykb.system.ry.util.poi.ExcelUtil;
import cn.zyq.ykb.system.common.BaseController;
import cn.zyq.ykb.system.annotation.Log;
import cn.zyq.ykb.system.ry.enums.BusinessType;
import cn.zyq.ykb.beans.user.PosUser;
import cn.zyq.ykb.service.user.PosUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import cn.zyq.ykb.system.common.BaseController;
import cn.zyq.ykb.system.common.PageParam;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * pos用户Controller
 *
 * @author SystemAuth
 * @date 2024-03-06
 */

@RestController(value = "MgtPosUserController")
@RequestMapping("/mgt/posUser")
@Api(tags = "pos用户接口")
public class PosUserController extends BaseController {

    @Autowired
    private PosUserService posUserService;

    /**
     * 查询pos用户列表
     */
    @ApiOperation(value = "列表", response = PosUser.class)
    @PostMapping("/list")
    public Object list(@RequestBody PageParam pageParam) {
        return this.posUserService.selectPosUserList(pageParam);
    }

     /**
      * 导出pos用户列表
      */
     @ApiOperation(value = "导出")
     @Log(title = "pos用户" , businessType = BusinessType.EXPORT)
     @PostMapping("/export")
     public void export(HttpServletResponse response, @RequestBody PageParam pageParam) {
         List<PosUser> list = posUserService.selectPosUserAllList(pageParam);
         ExcelUtil<PosUser> util = new ExcelUtil<PosUser>(PosUser. class);
         util.exportExcel(response, list, "pos用户数据");
     }

    /**
     * 获取pos用户详细信息
     */
    @ApiOperation(value = "详情", response = PosUser.class)
    @GetMapping(value = "/{posUserID}")
    public Object getInfo(@PathVariable("posUserID") Integer posUserID) {
        return this.posUserService.selectPosUserByPosUserID(posUserID);
    }
    /**
     * 获取pos用户详细信息
     */
    @ApiOperation(value = "详情", response = PosUser.class)
    @GetMapping(value = "/detail/{serviceID}")
    public Object getInfo(@PathVariable(value = "serviceID") String serviceID) {
        return this.posUserService.selectPosUserByServiceID(serviceID);
    }

    /**
     * 新增pos用户
     */
    @ApiOperation(value = "新增")
    @Log(title = "pos用户", businessType = BusinessType.INSERT)
    @PostMapping
    public Object add(@RequestBody PosUser posUser) {
        return this.posUserService.insertPosUser(posUser);
    }

    /**
     * 修改pos用户
     */
    @ApiOperation(value = "编辑")
    @Log(title = "pos用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public Object edit(@RequestBody PosUser posUser) {
        return this.posUserService.updatePosUser(posUser);
    }

    /**
     * 删除pos用户
     */
    @ApiOperation(value = "删除")
    @Log(title = "pos用户", businessType = BusinessType.DELETE)
    @DeleteMapping("/{posUserIDs}")
    public Object remove(@PathVariable Integer[] posUserIDs) {
        return this.posUserService.deletePosUserByPosUserIDs(posUserIDs);
    }
}
